package com.iman.common.annotationConfiguration;

import javax.sql.DataSource;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.iman.Confucius.service.FreeMarkerService;
import com.iman.common.hibernate.HibernateSupport;
import com.iman.common.springmvc.GlobalExceptionHandler;
/**
 *还有很多方式见 4.12.3.2 Combining Java and XML configuration 文档 
 */
//@Configuration
public class GlobalSpringAnnotationConfig {
	private @Autowired DataSource dataSource;
	private @Autowired SessionFactory sessionFactory;
	
	
	public @Bean FreeMarkerService freeMarkerService() {
	      return new com.iman.Confucius.service.impl.FreeMarkerServiceImpl( );
	  }
	
	
	//<bean id="exceptionHandler" class="com.iman.common.springmvc.GlobalExceptionHandler"></bean>
	public @Bean GlobalExceptionHandler exceptionHandler() {
	      return new com.iman.common.springmvc.GlobalExceptionHandler( );
	  }
	
	 /**
	  * <bean id="hibernateSupport" class="com.iman.common.hibernate.HibernateSupportImpl" scope="prototype">
			<property name="sessionFactory" ref="sessionFactory"/>
		</bean>
	*/
	public @Bean HibernateSupport hibernateSupport() {
	      return new com.iman.common.hibernate.HibernateSupportImpl( sessionFactory);
	  }
	/*
	<bean id="namedJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate" scope="prototype">
		<constructor-arg><ref bean="dataSource"/></constructor-arg>
	</bean>
	  * */
	public @Bean org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations namedJdbcTemplate() {
	      return new org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate(dataSource );
	  }
	
	
}
